<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>&nbsp;</title>
    </head>
    <body>

        <form id="fm" method="post" action="app/customer/update">
           <input type="hidden" name="id" value="${(customer.id)!}">
           <input type="hidden" id="imgData" name="head" value="${(customer.head)!}">
           <table style="width:450px;height:300px" cellspacing="5" border="0">
               <tbody>
                   <#if (customer.head)??>
                   <tr>
                       <td><img width="100" height="100" alt="头像" src="${(customer.head)!}"/></td>
                       <td>
                           <input type="file" id="file" name="file" value="上传头像" onchange="showImg()">
                       </td>
                   </tr>
                   <#else>
                   <tr>
                       <td id="showHead">
                           
                       </td>
                       <td>
                           <input type="file" id="file" name="file" value="上传头像" onchange="showImg()">
                       </td>
                   </tr>
                   </#if>
		           <tr>
		               <td>昵称:</td>
		               <td><input class="easyui-textbox" name="uname" style="width:400" value="${(customer.uname)!''}" data-options="required:true"></td>
		           </tr>
		           <tr>
		               <td>手机号:</td>
		               <td><input class="easyui-numberbox" max="99999999999" size="11" maxlength="11" name="mobile" style="width:400" value="${(customer.mobile)!}" data-options="required:true,min:0,precision:0,groupSeparator:'',decimalSeparator:'.'"></td>
		           </tr>
		           <tr>
		               <td>支付密码:</td>
		               <td><input class="easyui-textbox" name="pay_pwd" style="width:400" value="${(customer.pay_pwd)!}" data-options="required:true"></td>
		           </tr>
               </tbody>
               <tfoot>
                   <tr>
                        <td colspan="2">&nbsp;&nbsp;</td>
                   </tr>
                   <tr>
                       <td><a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">保存</a></td>
                       <#if user??>
                          <td align="center"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">重置</a></td>
                       <#else>
                           <td align="center"><a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeForm()" style="width:80px">关闭</a></td>
                           
                       </#if>
                   </tr>
               </tfoot>
           </table>
       
       <script type="text/javascript">
            function submitForm(){
                $('#fm').form('submit',{
                	success:function(){
                		$('#form').dialog('close');
                	}
                });
            }
            function clearForm(){
                $('#fm').form('clear');
            }
            function closeForm(){
            	$('#form').dialog('close');
            }
            
            function uploadHead(){
            	layer.open({type:2,content:'to?page=tools/upload'})
            }
            
            function showImg(){
            	var file=document.getElementById("file").files[0];
         	   
         	   var reader=new FileReader();
         	   reader.readAsDataURL(file);
         	   
         	   reader.onload=function(e){
         		   //获取图片的base64字符串
         		   var imgBase64Data=e.target.result;
         		   $("#showHead").text("");
         		   $("#showHead").append("<img width='100' height='100' src='"+imgBase64Data+"'/>");
         		   
         		   //截取字符串
         		   //var head=imgBase64Data.indexOf("4")+2;
         		   //imgBase64Data=imgBase64Data.substring(head,imgBase64Data.length-head);
         		   //将字符串中的"+" 替换成"%2B" 防止"+" 传过去变为空格
         		   var reg=new RegExp("\\+","g");
         		   imgBase64Data=imgBase64Data.replace(reg,"%2B");
         		   //存参数到隐藏的表单字段中
         		   $("#imgData").attr("value",imgBase64Data);
         	   }
            }
       </script>
    </body>
     
</html>